package com.dc.docs._888_面试.concurrent._2_cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Description: Cas Demo
 * @author: gdc
 * @date: 2021/6/15
 * @version 1.0
 */
public class Cas_1_AtomicInteger {

    public static void main(String[] args){
        // 主物理内存的值默认为 5
        AtomicInteger atomicInteger = new AtomicInteger(5);

        // 如果线程的期望值与物理内存的真实值一样，就修改为更新值
        System.out.println(atomicInteger.compareAndSet(5, 100) + "current data: " + atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(5, 200) + "current data: " + atomicInteger.get());
    }
}
